package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.utils.thread.WeThreadLocalUtil;
import com.heima.wemedia.service.WmMaterialService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author xiaquanen
 * @version 1.0
 * @project heima-leadnews
 * @date 2024/7/21 14:20:57
 */
@RestController
@RequestMapping("api/v1/material")
@Slf4j
public class WeMaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 分页列表查询
     *
     * @param wmMaterialDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto wmMaterialDto)
    {
        log.info(WeThreadLocalUtil.getUserId()+"");
       return wmMaterialService.list(wmMaterialDto);
    }

    /**
     * 上传图片
     *
     * @param multipartFile
     * @return
     */
    @PostMapping("/upload_picture")
    public ResponseResult uploadPicture(MultipartFile multipartFile)
    {
        return wmMaterialService.uploadPicture(multipartFile);
    }


    /**
     * 添加收藏
     *
     * @param id
     * @return
     */
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id)
    {
       return wmMaterialService.collect(id);
    }

    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id)
    {
       return wmMaterialService.collect(id);
    }

    /**
     * 删除素材
     *
     * @param id
     */
    @GetMapping("/del_picture/{id}")
    public ResponseResult delete(@PathVariable("id") Integer id)
    {
        wmMaterialService.removeById(id);
        return ResponseResult.okResult(null);
    }

}
